package wymiana.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import wymiana.domain.UploadedFiles;
import wymiana.domain.User;

@Repository
public class UploadedFileDao extends GenericDao<UploadedFiles> {

	@Autowired
	public UploadedFileDao(SessionFactory sf) {
		super(UploadedFiles.class, sf);
	}

	public UploadedFiles getUploadedFileById(Integer id) {
		UploadedFiles uploadedFile = (UploadedFiles) getById(id);
		return uploadedFile;
	}

	public List<UploadedFiles> getPersonalFiles(User u) {

		@SuppressWarnings("unchecked")
		List<UploadedFiles> ll = getHibernateTemplate()
				.find("select file from UploadedFiles file left join file.dgroup gr left join gr.users us where file.createUser=? or us = ? or gr.createUser = ?",
						u, u, u);

		return ll;
	}

}
